<template>
    <div class="color-block" :class="{active:active}" :style="'backgroundColor:' + color.color_num">
        <svg-icon name="checkbox-active-shadow" alt="" />
        <span v-text="color.color_name || color.name"></span>
    </div>
</template>
<script>
export default {
    name: "ColorBlock",
    props: {
        name: {},
        color: {
            type: Object,
            default: () => { return {} },
        },
        active: {
            type: Boolean,
            default: true,
        },
    },
    data () {
        return {};
    },
    methods: {
    },
};
</script>
<style lang="scss" scoped>
.color-block {
    box-sizing: border-box;
    width: 24px;
    height: 24px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;

    & > svg {
        display: none;
        height: 18px;
        width: 18px;
        pointer-events: none;
    }

    & > span {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: 100%;
        background: #303133;
        white-space: nowrap;
        padding: 8px 10px;
        color: #fff;
        border-radius: 4px;
        margin-bottom: 8px;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.5s;
        &::after {
            content: '';
            position: absolute;
            left: 50%;
            margin-left: -3px;
            bottom: -3px;
            width: 6px;
            height: 6px;
            background: #303133;
            transform: rotate(45deg);
        }
    }

    &:hover span {
        opacity: 1;
    }
    &.active {
        & > svg {
            display: block;
        }
    }
}
</style>
